import sys
sys.path.append(r'C:\Users\zhangjuntao\anaconda3\Lib\site-packages')

from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.ecc.v20181213 import ecc_client, models

def correct_essay(secret_id, secret_key, essay_text):
    # 初始化认证
    cred = credential.Credential(secret_id, secret_key)
    http_profile = HttpProfile()
    http_profile.endpoint = "ecc.tencentcloudapi.com"

    # 创建客户端
    client_profile = ClientProfile()
    client_profile.httpProfile = http_profile
    client = ecc_client.EccClient(cred, "", client_profile)

    # 构建请求
    req = models.CorrectMultiImageRequest()
    req.EnglishEssay = essay_text  # 替换为实际作文内容
    req.Score = 100.0  # 满分100分
    req.SessionId = "test_session_123"  # 会话ID可自定义

    # 发送请求
    response = client.CorrectMultiImage(req)
    return response

if __name__ == "__main__":
    # 替换成您的实际密钥
    SECRET_ID = "AKIDgFZdR01oLdgT0GG0TfiV1HGzSfiUzDAr"
    SECRET_KEY = "XnmVyA5k9H8i26tPfeNq54nFQLzNUKuD"
    
    # 示例作文内容
    sample_essay = """
    In recent years, the problem of environmental pollution has became increasingly 
    serious. Many factories pours waste water into rivers without any treatment, 
    which leads to the death of a large number of fishes. We must takes measures 
    to solve this problem.
    """
    
    # 调用批改接口
    result = correct_essay(SECRET_ID, SECRET_KEY, sample_essay)
    
    # 解析结果
    print("综合评分:", result.TotalScore)
    print("错误详情:")
    for error in result.Errors:
        print(f"- 位置[{error.StartPosition}-{error.EndPosition}]")
        print(f"  原句: {error.OriginalText}")
        print(f"  建议: {error.CorrectedText}")
        print(f"  错误类型: {error.TypeDescription}")